package de.luisoft.web.servlet;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.Entity;

import de.luisoft.dao.MyDAO;

public class RegisterServlet extends HttpServlet {

	private static final Logger log = Logger.getLogger(RegisterServlet.class.getName());
	/**
	 * 
	 */
	private static final long serialVersionUID = 7161146165061872986L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		log.info("doGet");
		
		resp.setContentType("text/plain");
		String key = req.getParameter("id");
		if (key != null) {
			try {
				MyDAO m = new MyDAO();
				Entity e = m.get(key);
				Entity e1 = m.verify(e);

				log.info("register" + key + ";" + e1);

				resp.getWriter().append("Hallo " + e1.getProperty("vorname") + " " + e1.getProperty("name") + ",\n\n");
				resp.getWriter().append("die Auswahl " + e1.getProperty("select") + " wurde übernommen.\n\n");
				resp.getWriter().append("Dein augustinianum.");
				
			} catch (Exception e) {
				resp.getWriter().append("Sorry, failed" + e);
			}
		}

		resp.getWriter().close();
	}

}
